package com.demo;

import cn.hutool.core.util.XmlUtil;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.xpath.XPathConstants;
import java.io.File;

/**
 * @Auther: Code
 * @Date: 2018/9/9 18:02
 * @Description: 批量重命名文件
 */
public class XpathReader {

    public static void node(NodeList list){
        for (int i = 0; i <list.getLength() ; i++) {
            Node node = list.item(i);
            NodeList childNodes = node.getChildNodes();
            for (int j = 0; j <childNodes.getLength() ; j++) {
                if (childNodes.item(j).getNodeType()==Node.ELEMENT_NODE) {
                    System.out.print(childNodes.item(j).getNodeName() + ":");
                    System.out.println(childNodes.item(j).getFirstChild().getNodeValue());
                }
            }
        }
    }

    public static void main(String[] args) {
        File file = new File("C:/Users/mifei/Documents/WeChat Files/mefly521/FileStorage/File/2021-09/计算工具/jgtx2.xml");
        Document docResult= XmlUtil.readXML(file);
       // Object value = XmlUtil.getByXPath("//JGTX/CLZFFQYTX/QX/MXXX/QY", docResult, XPathConstants.STRING);
        NodeList nodeList = XmlUtil.getNodeListByXPath("//JGTX/CLZFFQYTX/QX/MXXX/QY", docResult);
        for (int i = 0; i < nodeList.getLength(); i++) {
            System.out.println(nodeList.item(i).getFirstChild().getNodeValue());
        }


    }
}